<!-- 组件说明 -->
<template>
    <div class='news'>
        <el-row>
            <el-col :span="24" class="newsbanner">
            </el-col>
        </el-row>
        <el-tabs v-show="isNewsList" v-model="activenews" type="border-card" style="padding-bottom:50px">
          <el-tab-pane label="中心新闻"  name="centerNews">
            <el-row v-for="(item,index) in centerNews" :key="index">
              <el-col :span="20" :offset="2">
                <div class="newsdiv">
                  <div class="newsimg">
                    <img class="slimg" :src="getImgUrl(item.image)" alt="">
                  </div>
                  <div @click="getDetialsNew(item.id)" class="newstitle newsitem">{{item.title}}</div>
                  <div class="newsdes newsitem">{{item.description}}</div>
                  <div class="newstime newsitem">{{item.createtime}}</div>
                </div>
              </el-col>
            </el-row>
            <el-pagination
              @current-change="handleCurrentChange"
              background
              layout="prev, pager, next"
              :total="enterPageNumber">
            </el-pagination>
          </el-tab-pane>
            <el-tab-pane label="公司新闻"  name="company">
                <el-row v-for="(item,index) in companyNews" :key="index">
                    <el-col :span="20" :offset="2">
                        <div class="newsimg">
                            <img class="slimg" :src="getImgUrl(item.image)" alt="">
                        </div>
                        <div class="newsdiv">
                            <div @click="getDetialsNew(item.id)" class="newstitle newsitem">{{item.title}}</div>
                            <div class="newsdes newsitem">{{item.description}}</div>
                            <div class="newstime newsitem">{{item.createtime}}</div>
                        </div>
                    </el-col>
                </el-row>
              <el-pagination
                @current-change="handleCurrentChange"
                background
                layout="prev, pager, next"
                :total="companyPageNumber">
              </el-pagination>
            </el-tab-pane>
            <el-tab-pane label="行业新闻" name="tradeNews">
                <el-row v-for="(item,index) in tradeNews" :key="index">
                    <el-col :span="20" :offset="2">
                        <div class="newsimg">
                            <img class="slimg" :src="getImgUrl(item.image)" alt="">
                        </div>
                        <div class="newsdiv">
                            <div @click="getDetialsNew(item.id)" class="newstitle newsitem">{{item.title}}</div>
                            <div class="newsdes newsitem">{{item.description}}</div>
                            <div class="newstime newsitem">{{item.createtime}}</div>
                        </div>
                    </el-col>
                </el-row>
              <el-pagination
                @current-change="handleCurrentChange"
                background
                layout="prev, pager, next"
                :total="tranPageNumber">
              </el-pagination>
            </el-tab-pane>
        </el-tabs>

        <el-row v-show="!isNewsList">
            <el-page-header @back="goBack" content="新闻详情"></el-page-header>
            <el-col :span="24" class="newdetial_title">
                {{title}}
            </el-col>
            <el-col :span="24" class="newdeital_time">
                {{times}}
            </el-col>
            <el-col :span="24" class="newdeital_content">
                <div id="newdeital_content"></div>
            </el-col>
        </el-row>
        <common-footer ></common-footer>
    </div>
</template>

<script>
    import {getNewsList,getNewsDetial} from '../request/api'
    import CommonFooter from '../components/common/Footer'
    import Bus from '../request/bus'
    import axios from 'axios'
    export default {
        components: {
            CommonFooter
        },
        data () {
            return {
                url:'http://39.99.217.167:8080',
                companyNews:[
                ],
                tradeNews:[
                ],
                centerNews:[
                ],
                activenews:'centerNews',
                isNewsList:true,
                title:'123456789',
                times:'2019.12.12',
                newsid:'',
                newsdestial:'',
                //行业新闻总页数
                tranPageNumber:'',
                //中心新闻总页数
                enterPageNumber:'',
                //公司新闻
                companyPageNumber:'',
                pageSize:10,
                total:'',
                //新闻类型
                newsType:''
            };
        },
        computed: {

        },
        created(){
            //新闻列表
            Bus.$on('newslist',val=>{
                this.activenews = val;
                this.isNewsList = true;
                this.getNewsList();
            });
            //获取新闻id
            Bus.$on('newsid',val=>{

                this.newsid = val;
                this.isNewsList = false;
                this.getDetialsNew(this.newsid);
            });
        },
        methods: {
          getImgUrl(url){
            return this.url+url;
          },
          //设置当前显示新闻类型
          changeNewsType(type){
            alert(type)
          },
            //详情返回列表页
            goBack(){
                this.isNewsList = true;
                this.getNewsList();
            },
            //获取新闻列表
            getNewsList(){

                getNewsList().then(res=>{
                    this.tradeNews = res.tradeNews;
                    this.companyNews = res.companyNews;
                    this.centerNews = res.centerNews;
                });
            },
            //获取新闻详情
            getNewsmx(){
                /*axios.get('/getNewsDetial?id='+this.newid).then(res=>{
                    console.log(res)
                })*/
                /*getNewsDetial('/getNewsDetial?id='+this.newid).then(res=>{
                    this.title = res.title;
                    this.times = res.createtime
                    this.newsdestial = res.content;
                    document.getElementById('newdeital_content').innerHTML=res.content
                });*/
            },
            getDetialsNew(newid){

                axios.get(this.url+'/enterprise/selectNewsById?id='+newid).then(res=>{
                /*  alert(JSON.stringify(res))*/
                  this.title = res.data.title;
                  this.times = res.data.createtime;
                  this.newsdestial = res.data.content;
                  this.isNewsList = false;
                  /*console.log(JSON.stringify(this.newsdestial))*/
                  document.getElementById('newdeital_content').innerHTML=this.newsdestial

                })

               /* getNewsDetial(newid).then(res=>{
                  alert(JSON.stringify(res))
                    this.title = res.title;
                    this.times = res.createtime
                    this.newsdestial = res.content;
                    this.isNewsList = false;
                    document.getElementById('newdeital_content').innerHTML=res.content
                });*/
            },
          //新闻分页
          handleCurrentChange(pageNum) {
            axios.get(this.url+'/enterprise/pageNews/?pageNum='+pageNum+'&pageSize='+this.pageSize+'&type='+this.activenews).then(res=>{
              //
              if(res.data != null){
              /*  console.log(JSON.stringify(res.data))*/
                let news = JSON.parse(JSON.stringify(res.data));
                /*console.log();*/
                //如果等于中心新闻
                if(this.activenews == 'centerNews'){
                  //新闻总数
                  let count = res.data.total
                   // this.enterPageNumber = Math.floor(count % 10 == 0?count/10:count/10 + 1)
                    this.centerNews = res.data.newsPage;

                    //如果等于行业新闻
                }else if(this.activenews == 'tradeNews'){
                  //新闻总数
                  let count = res.data.total
                  //this.tranPageNumber = Math.floor(count % 10 == 0?count/10:count/10 + 1)
                  this.tradeNews = res.data.newsPage;
                  //公司新闻
                }else{
                  //新闻总数
                  let count = res.data.total
                 // this.companyNewsCount = Math.floor(count % 10 == 0?count/10:count/10 + 1)

                  this.companyNews = res.data.newsPage;
                }
              }
             /* this.title = res.data.title;
              this.times = res.data.createtime;
              this.newsdestial = res.data.content;
              this.isNewsList = false;
              console.log(JSON.stringify(this.newsdestial))
              document.getElementById('newdeital_content').innerHTML=this.newsdestial*/
            })

          },
          //新闻分页
          categroyNews() {
            axios.get(this.url+'/enterprise/categroyNewsTotal').then(res=>{
              //{"tradeNewsCount":1,"centerNewsCount":11,"companyNewsCount":13}
              if(res != null){
                //this.tranPageNumber = Math.floor(res.data.tradeNewsCount % 10 == 0?res.data.tradeNewsCount/10:res.data.tradeNewsCount/10 + 1);
                this.tranPageNumber = res.data.tradeNewsCount;

                this.enterPageNumber = res.data.centerNewsCount;

                this.companyPageNumber = res.data.companyNewsCount;

              }
            })

          }
        },
        mounted() {
            /*this.getNewsList();*/
            this.categroyNews();
            this.handleCurrentChange(1);

        },
      //监听面板切换事件
      watch : {
        'activenews':function(val) { //监听切换状态-计划单
          this.activenews = val;
          this.handleCurrentChange(1);

        },
      },
        //生命周期 - 创建之前
        beforeCreate() {},
        //生命周期 - 挂载之前
        beforeMount() {},
        //生命周期 - 更新之前
        beforeUpdate() {},
        //生命周期 - 更新之后
        updated() {},
        //生命周期 - 销毁之前
        beforeDestroy() {},
        //生命周期 - 销毁完成
        destroyed() {},
        //如果页面有keep-alive缓存功能，这个函数会触发
        activated() {},
    }
</script>
<style>
.el-page-header{
    padding: 20px 10px;
}
.el-tabs__nav{
    padding-left: 8%;
}
.el-tabs--border-card>.el-tabs__header .el-tabs__item{
    color: #000 !important;
}
.el-tabs--border-card>.el-tabs__header .el-tabs__item.is-active,.el-tabs--border-card>.el-tabs__header .el-tabs__item:not(.is-disabled):hover{
    color: #ffff !important;
    background-color: #999999 !important;
}
.el-tabs--border-card{
    border: 0px solid #DCDFE6 !important;
}
#newdeital_content{
    width: 80%;
    margin-left:10%;
    margin-bottom:50px;
}
</style>
<style scoped>
.newstitle:hover{
    color: #415cad;
    cursor: pointer;
}
.newdetial_title{
    height: 50px;
    line-height: 50px;
    font-size: 30px;
    color: #415cad;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.newdeital_time{
    height: 20px;
    line-height: 20px;
    color: #999999;
    font-size: 14px;
    margin-bottom: 35px;
}
.newsdiv{
    height:100px;
    border-bottom: solid 1px #eee;
    margin-bottom: 15px;
    margin-left: -18px;
    /* padding-left: 100px; */
}
.slimg{
    width: 130px;
    height: 100px;;
}
.newsimg{
    float: right;
    height:100px;
    margin-right:20px
}
.newstitle{
    height: 30px;
    line-height: 40px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.newsdes{
    font-size: 13px;
    height: 40px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 40px;
}
.newstime{
    font-size: 12px;
    color: #757272 !important;
    height: 30px;
    line-height: 30px;
}
.newsitem{
    text-align: left;
    color: #000;
}
.newsbanner{
    background-image: url('../assets/img/compent/newsbanner.png');
    height: 300px;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
}
</style>
